<?php

namespace frontend\controllers;

use Yii;
use frontend\models\Register;
use frontend\models\GrpCity;
use yii\helpers\Url;

class RegisterController extends \yii\web\Controller
{
    public function actionIndex()
    {
        $model = new Register();
        $province=GrpCity::province();
        if ($model->load(Yii::$app->request->post())) {
            if ($model->validate() && $model->signup()) {
                $model = new Register();
                return $this->render('submitSuccess',[
                    'redirectUrl'=>Url::to(['index']),
                    'msg'=>'注册成功',
                    'status'=>'success',
                ]);
            }
        }
    
        return $this->render('index', [
            'model' => $model,
            'province' => $province,
        ]);
    }
    //ajax取城市
    public function actionCity()
    {
        if(Yii::$app->request->isAjax&&Yii::$app->request->post('id'))
        {
            if (Yii::$app->request->post('q')=='city')
            {
                $value=GrpCity::city(intval(Yii::$app->request->post('id')));
            }
            elseif(Yii::$app->request->post('q')=='area2')
            {
                $value=GrpCity::area2(intval(Yii::$app->request->post('id')));
            }
            elseif (Yii::$app->request->post('q')=='area')
            {
                $value=GrpCity::area(intval(Yii::$app->request->post('id')));
            }
            echo json_encode($value,JSON_UNESCAPED_UNICODE);
        }
    }
}
